﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.IO;
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!File.Exists(Server.MapPath("userInfor.xml")))
        {


           XmlWriter xwriter = XmlWriter.Create(Server.MapPath("userInfor.xml"));
            xwriter.WriteStartDocument(true);
            //写入根元素
            xwriter.WriteStartElement("userinfor");
            xwriter.WriteEndElement();
            xwriter.WriteEndDocument();

            xwriter.Close();
            
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text != "" && TextBox2.Text != "")
        {
            XmlDocument xdoc = new XmlDocument();
            xdoc.Load(Server.MapPath("userInfor.xml"));

            XmlNode root = xdoc.SelectSingleNode("userinfor");
            XmlElement regtime = xdoc.CreateElement("infor");
            regtime.SetAttribute("regtime", DateTime.Now.ToString("yyyy-MM-dd"));
            XmlElement uname = xdoc.CreateElement("uname");
            uname.InnerText = TextBox1.Text;
            XmlElement upwd = xdoc.CreateElement("upwd");
            upwd.InnerText = TextBox2.Text;
            regtime.AppendChild(uname);
            regtime.AppendChild(upwd);
           root.AppendChild(regtime);
            xdoc.Save(Server.MapPath("userInfor.xml"));

        
        }
    }
}
